package cjgl.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import cjgl.dao.ConnectionFactory;

/**
 * Application Lifecycle Listener implementation class contextListener
 *
 */
@WebListener
public class contextListener implements ServletContextListener {
    /**
     * Default constructor. 
     */
    public contextListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent sce)  { 
         // TODO Auto-generated method stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent sce)  { 
         ServletContext sctxt = sce.getServletContext();
         String dbName= sctxt.getInitParameter("dbName");
         String username = sctxt.getInitParameter("username");
         String pwd = sctxt.getInitParameter("pwd");
        
         if(dbName!=null) {
        	 ConnectionFactory.setDbName(dbName);
         }
         
         if(username!=null) {
        	 ConnectionFactory.setUsername(username);
         }
         
         if(pwd!=null) {
        	 ConnectionFactory.setPassword(pwd);
         }
    }
	
}
